package in.srain.cube.request;

import java.io.Serializable;

public class FailData implements Serializable {

    private IRequest<?, ?> mRequest;
    private Exception mException;

    private FailData(IRequest<?, ?> request, Exception ex) {
        mRequest = request;
        mException = ex;
    }

    public static FailData fromNullObject(IRequest<?, ?> request) {
        return new FailData(request, new ProcessOriginDataFromServerReturnNullException());
    }

    public static FailData fromException(IRequest<?, ?> request, Exception ex) {
        return new FailData(request, ex);
    }

    public static FailData customError(IRequest<?, ?> request, int code, String message) {
        return new FailData(request, new CustomNetworkException(code, message));
    }

    public static FailData inputError(IRequest<?, ?> request) {
        return new FailData(request, new InputException());
    }

    public static FailData networkError(IRequest<?, ?> request) {
        return new FailData(request, new NoNetWorkException());
    }

    public Exception getException() {
        return mException;
    }

    public IRequest<?, ?> getRequest() {
        return mRequest;
    }

    public static class BaseException extends Exception {
        BaseException(String message) {
            super(message);
        }
    }

    public static class InputException extends BaseException {
        InputException() {
            super("InputException");
        }
    }

    public static class NoNetWorkException extends BaseException {
        NoNetWorkException() {
            super("NoNetWorkException");
        }
    }

    public static class ProcessOriginDataFromServerReturnNullException extends BaseException {
        ProcessOriginDataFromServerReturnNullException() {
            super("ProcessOriginDataFromServerReturnNullException");
        }
    }

}
